;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;                                                                           ;;
;;                     Unofficial Chinese Clone Support                      ;;
;;                      http://code.google.com/p/uccs/                       ;;
;;                                                                           ;;
;;                            Version 0.21                                   ;;
;;                                                                           ;;
;;                            by Tomas Rimkus                                ;;
;;             (based on work by Brian Jorgensen, Leon and Micha)            ;;
;;                                                                           ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;Workaround for alt-tab
$*Tab::Send {Blind}{Tab}

;;SwapWinAndAlt plus RemapRightWinToFn & RemapRightWinToCtrl
$*LWin::PreferenceKeyDown("LWin", "SwapWinAndAlt", "LAlt")
$*LWin Up::PreferenceKeyUp("LWin", "SwapWinAndAlt", "LAlt")
$*RWin::RightModifierKeyDown("RWin", "LControl down}{Ralt")
$*RWin Up::RightModifierKeyUp("RWin", "LControl up}{Ralt")

$*LAlt::PreferenceKeyDown("LAlt", "SwapWinAndAlt", "LWin")
$*LAlt Up::PreferenceKeyUp("LAlt", "SwapWinAndAlt", "LWin")
$*RAlt::RightModifierKeyDown("LControl down}{Ralt", "RWin")
$*RAlt Up::RightModifierKeyUp("LControl up}{Ralt", "RWin")

RightModifierKeyDown(key, swappedKey)
{
	global
	if (RemapRightWinToFn && isRWin(key, swappedKey))
		PreferenceKeyFnDown("{RWin Down}", "RemapRightWinToFn")
	else if (RemapRightWinToCtrl && isRWin(key, swappedKey))
		Send {Blind}{RCtrl Down}
	else if (SwapWinAndAlt)
		Send {Blind}{%swappedKey% Down}
	else
		Send {Blind}{%key% Down}
}

RightModifierKeyUp(key, swappedKey)
{
	global
	if (RemapRightWinToFn && isRWin(key, swappedKey))
		PreferenceKeyFnUp("{RWin Up}", "RemapRightWinToFn")
	else if (RemapRightWinToCtrl && isRWin(key, swappedKey))
		Send {Blind}{RCtrl Up}
	else if (SwapWinAndAlt)
		Send {Blind}{%swappedKey% Up}
	else
		Send {Blind}{%key% Up}
}

isRWin(key, swappedKey)
{
	global
	Return ((!SwapWinAndAlt && key == "RWin") 
	|| (SwapWinAndAlt && swappedKey == "RWin"))
}
;;Win+Alt+Backspace = task manager
;;Ctrl+Alt+Backspace = task manager
#!Backspace::
^!Backspace::Run taskmgr.exe

;; {Capslock} --> {Shift} or {Capslock} --> {Ctrl}
$*CapsLock::
	SetKeyDelay, -1
	if (RemapCapsLockToShift) 
		Send, {Blind}{Shift Down}
	else if (RemapCapsLockToCtrl)
		Send {Blind}{RCtrl Down}
	else 
	{
		if (GetKeyState("CapsLock", "T")) {
			SetCapsLockState, Off
		} else {
			SetCapsLockState, On
		}
		KeyWait, CapsLock
	}
	Return

$*CapsLock Up::
	SetKeyDelay, -1
	if (RemapCapsLockToShift)
		Send, {Blind}{Shift Up}
	else if (RemapCapsLockToCtrl)
		Send {Blind}{RCtrl Up}
	Return
